#include "janelaprincipal.h"
#include "ui_janelaprincipal.h"

janelaPrincipal::janelaPrincipal(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::janelaPrincipal)
{
    ui->setupUi(this);
    ui->statusBar->showMessage(tr("Pronto"));
}

janelaPrincipal::~janelaPrincipal()
{
    delete ui;
}

void janelaPrincipal::on_actionAgente_triggered()
{
    ui->glwidget->cliqueBotaoAgente();    
    ui->actionAgente->setChecked(true);
    ui->actionObjetivo->setChecked(false);
    ui->actionObstaculo->setChecked(false);
    ui->actionNPC->setChecked(false);
    ui->actionWaypoint->setChecked(false);
    ui->actionInserirTerreno->setChecked(false);
    ui->statusBar->showMessage(tr("Insira o Agente."));
}

void janelaPrincipal::on_actionObstaculo_triggered()
{
    ui->glwidget->cliqueBotaoObstaculo();
    ui->actionAgente->setChecked(false);
    ui->actionObjetivo->setChecked(false);
    ui->actionObstaculo->setChecked(true);
    ui->actionNPC->setChecked(false);
    ui->actionWaypoint->setChecked(false);
    ui->actionInserirTerreno->setChecked(false);
    ui->statusBar->showMessage(tr("Insira os Obstaculos."));
}

void janelaPrincipal::on_actionObjetivo_triggered()
{
    ui->glwidget->cliqueBotaoObjetivo();
    ui->actionAgente->setChecked(false);
    ui->actionObjetivo->setChecked(true);
    ui->actionObstaculo->setChecked(false);
    ui->actionNPC->setChecked(false);
    ui->actionWaypoint->setChecked(false);
    ui->actionInserirTerreno->setChecked(false);
    ui->statusBar->showMessage(tr("Insira o Objetivo."));
}

void janelaPrincipal::on_actionNPC_triggered()
{
//    ui->glwidget->pause();
    ui->statusBar->showMessage(tr("Escolha o algoritmo desejado e insira os NPC's."));
    QMenu *menu = new QMenu();
    menu->addAction("Perseguicao", this, SLOT(on_actionPerseguicao_activated()));
    menu->addAction("Wavefront Planner", this, SLOT(on_actionWavefrontPlanner_activated()));
    menu->addAction("Waypoint Navigation", this, SLOT(on_actionWaypointNavigation_activated()));
    menu->addAction("Campos Potenciais", this, SLOT(on_actionCampos_Potenciais_activated()));
    QPoint q = QCursor::pos();
    q.setX(q.x()+40);
    menu->exec(QCursor::pos());
    ui->glwidget->cliqueBotaoNPC();
    ui->actionAgente->setChecked(false);
    ui->actionObjetivo->setChecked(false);
    ui->actionObstaculo->setChecked(false);
    ui->actionNPC->setChecked(true);
    ui->actionWaypoint->setChecked(false);
    ui->actionInserirTerreno->setChecked(false);
}

void janelaPrincipal::on_actionWaypoint_triggered()
{
    ui->glwidget->cliqueBotaoWaypoint();
    ui->actionAgente->setChecked(false);
    ui->actionObjetivo->setChecked(false);
    ui->actionObstaculo->setChecked(false);
    ui->actionNPC->setChecked(false);
    ui->actionWaypoint->setChecked(true);
    ui->actionInserirTerreno->setChecked(false);
    ui->statusBar->showMessage(tr("Insira os Waypoints."));
}

void janelaPrincipal::on_Play_clicked()
{
    ui->glwidget->play();    
    ui->statusBar->showMessage(tr("Em execucao!"));
}

void janelaPrincipal::on_Pause_clicked()
{
    ui->glwidget->pause();
    ui->statusBar->showMessage(tr("Em pausa."));
}

void janelaPrincipal::on_actionConfigura_es_triggered()
{
    ui->glwidget->pause();
    DialogoConfiguracoes d;
    d.exec();
    d.show();

}

void janelaPrincipal::on_actionPerseguicao_activated()
{   
    ui->glwidget->setAlgoritmo(2);
}

void janelaPrincipal::on_actionWaypointNavigation_activated()
{
    ui->glwidget->setAlgoritmo(1);
}

void janelaPrincipal::on_actionLimpar_triggered()
{
    ui->glwidget->limparCenario();
}


void janelaPrincipal::on_actionWavefrontPlanner_activated()
{
    ui->glwidget->setAlgoritmo(0);
}

void janelaPrincipal::on_actionCampos_Potenciais_activated()
{
    ui->glwidget->setAlgoritmo(3);
}

void janelaPrincipal::on_actionSair_triggered()
{
    exit(0);
}

void janelaPrincipal::on_actionInserirTerreno_triggered()
{
    ui->glwidget->pause();
    DialogoValorTerreno d;
    d.exec();
    d.show();
    ui->glwidget->setValorTerreno(d.valorTerreno);   
    ui->glwidget->cliqueBotaoTerreno();
    ui->actionAgente->setChecked(false);
    ui->actionObjetivo->setChecked(false);
    ui->actionObstaculo->setChecked(false);
    ui->actionNPC->setChecked(false);
    ui->actionWaypoint->setChecked(false);
    ui->actionInserirTerreno->setChecked(true);
    ui->statusBar->showMessage(tr("Insira o Terreno."));
}
